﻿using doveData.XmlScripts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace doveData
{
    class ConsoleControl
    {

        public static void Intro()
        {
            Console.WindowWidth = 120;
            int flag = -1;
            while (true)
            {
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.WriteLine("\t\t\t\t\t*      欢迎来到鸽地图服务中心！    *");
                Console.WriteLine("\t\t\t\t\t*        请输入操作码选择服务：    *");
                Console.WriteLine("\t\t\t\t\t*         1.出行规划&信息查询      *");
                Console.WriteLine("\t\t\t\t\t*         2.后台数据处理           *");
                Console.WriteLine("\t\t\t\t\t************************************");

                Console.Write("\t\t\t\t\t");
                try
                {
                    flag = int.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("\t\t\t\t\t抱歉，请输入有效的操作码");
                    continue;
                }
                switch (flag)
                {
                    case 1:
                        FrontDuang();
                        break;
                    case 2:
                        DataBase();
                        break;
                    default:
                        Console.WriteLine("\t\t\t\t\t抱歉，您的输入有误，请重试");
                        break;
                }
            }
        }

        static void Line()
        {
            LineXml myLine = new LineXml();
            int num;
            while (true)
            {
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.WriteLine("\t\t\t\t\t*      欢迎来到鸽线路服务中心！    *");
                Console.WriteLine("\t\t\t\t\t*        请输入操作码选择服务：    *");
                Console.WriteLine("\t\t\t\t\t*         1.查询地铁线路信息       *");
                Console.WriteLine("\t\t\t\t\t*         2.增加新的线路信息       *");
                Console.WriteLine("\t\t\t\t\t*         3.修改已有线路信息       *");
                Console.WriteLine("\t\t\t\t\t*         4.删除已有线路信息       *");
                Console.WriteLine("\t\t\t\t\t*         0.退出操作               *");
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.Write("\t\t\t\t\t");
                try
                {
                    num = int.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("\t\t\t\t\t抱歉，请输入有效的操作码");
                    continue;
                }
                switch (num)
                {
                    case 1:
                        {
                            myLine.Output();
                            break;
                        }
                    case 2:
                        {
                            myLine.AddXElement();
                            break;
                        }
                    case 3:
                        {
                            myLine.ModifyElement();
                            break;
                        }
                    case 4:
                        {
                            myLine.DeleteElement();
                            break;
                        }
                    default:
                        {
                            Console.WriteLine("\t\t\t\t\t输入指令有误！");
                            break;
                        }
                }
                if (num == 0) break;
            }
        }

        static void Hotel()
        {
            HotelXml myHotel = new HotelXml();
            int num;
              while (true)
            {
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.WriteLine("\t\t\t\t\t*      欢迎来到鸽酒店服务中心！    *");
                Console.WriteLine("\t\t\t\t\t*        请输入操作码选择服务：    *");
                Console.WriteLine("\t\t\t\t\t*         1.查询酒店信息           *");
                Console.WriteLine("\t\t\t\t\t*         2.增加新的酒店信息       *");
                Console.WriteLine("\t\t\t\t\t*         3.修改已有酒店信息       *");
                Console.WriteLine("\t\t\t\t\t*         4.删除已有酒店信息       *");
                Console.WriteLine("\t\t\t\t\t*         0.退出操作               *");
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.Write("\t\t\t\t\t");
                try
                {
                    num = int.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("\t\t\t\t\t抱歉，请输入有效的操作码");
                    continue;
                }
                switch (num)
                {
                    case 1:
                        {
                            myHotel.Output();
                            break;
                        }
                    case 2:
                        {
                            myHotel.AddXElement();
                            break;
                        }
                    case 3:
                        {
                            myHotel.ModifyElement();
                            break;
                        }
                    case 4:
                        {
                            myHotel.DeleteElement();
                            break;
                        }
                    default:
                        {
                            Console.WriteLine("\t\t\t\t\t输入指令有误！");
                            break;
                        }
                }
                if (num == 0) break;
            }
        }

        static void Market()
        {
            MarketXml myMarket = new MarketXml();
            int num;
            while (true)
            {
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.WriteLine("\t\t\t\t\t*      欢迎来到鸽商店服务中心！    *");
                Console.WriteLine("\t\t\t\t\t*        请输入操作码选择服务：    *");
                Console.WriteLine("\t\t\t\t\t*         1.查询商店信息           *");
                Console.WriteLine("\t\t\t\t\t*         2.增加新的商店信息       *");
                Console.WriteLine("\t\t\t\t\t*         3.修改已有商店信息       *");
                Console.WriteLine("\t\t\t\t\t*         4.删除已有商店信息       *");
                Console.WriteLine("\t\t\t\t\t*         0.退出操作               *");
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.Write("\t\t\t\t\t");
                try
                {
                    num = int.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("\t\t\t\t\t抱歉，请输入有效的操作码");
                    continue;
                }
                switch (num)
                {
                    case 1:
                        {
                            myMarket.Output();
                            break;
                        }
                    case 2:
                        {
                            myMarket.AddXElement();
                            break;
                        }
                    case 3:
                        {
                            myMarket.ModifyElement();
                            break;
                        }
                    case 4:
                        {
                            myMarket.DeleteElement();
                            break;
                        }
                    default:
                        {
                            Console.WriteLine("\t\t\t\t\t输入指令有误！");
                            break;
                        }
                }
                if (num == 0) break;
            }
        }

        static void Food()
        {
            FoodXml myFood = new FoodXml();
            int num;
            while (true)
            {
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.WriteLine("\t\t\t\t\t*      欢迎来到鸽饭店服务中心！    *");
                Console.WriteLine("\t\t\t\t\t*        请输入操作码选择服务：    *");
                Console.WriteLine("\t\t\t\t\t*         1.查询饭店信息           *");
                Console.WriteLine("\t\t\t\t\t*         2.增加新的饭店信息       *");
                Console.WriteLine("\t\t\t\t\t*         3.修改已有饭店信息       *");
                Console.WriteLine("\t\t\t\t\t*         4.删除已有饭店信息       *");
                Console.WriteLine("\t\t\t\t\t*         0.退出操作               *");
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.Write("\t\t\t\t\t");
                try
                {
                    num = int.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("\t\t\t\t\t抱歉，请输入有效的操作码");
                    continue;
                }
                switch (num)
                {
                    case 1:
                        {
                            myFood.Output();
                            break;
                        }
                    case 2:
                        {
                            myFood.AddXElement();
                            break;
                        }
                    case 3:
                        {
                            myFood.ModifyElement();
                            break;
                        }
                    case 4:
                        {
                            myFood.DeleteElement();
                            break;
                        }
                    default:
                        {
                            Console.WriteLine("\t\t\t\t\t输入指令有误！");
                            break;
                        }
                }
                if (num == 0) break;
            }
        }

        static void DataBase()
        {
            int flag = -1;
            while (true)
            {
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.WriteLine("\t\t\t\t\t*      欢迎来到鸽地图服务中心！    *");
                Console.WriteLine("\t\t\t\t\t*        请输入操作码选择服务：    *");
                Console.WriteLine("\t\t\t\t\t*         1.查询地铁线路信息       *");
                Console.WriteLine("\t\t\t\t\t*         2.查询酒店数据信息       *");
                Console.WriteLine("\t\t\t\t\t*         3.查询商店数据信息       *");
                Console.WriteLine("\t\t\t\t\t*         4.查询饭店数据信息       *");
                Console.WriteLine("\t\t\t\t\t************************************");
                Console.Write("\t\t\t\t\t");
                try
                {
                    flag = int.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("\t\t\t\t\t抱歉，请输入有效的操作码");
                    continue;
                }
                switch (flag)
                {
                    case 1:
                        Line();
                        break;
                    case 2:
                        Hotel();
                        break;
                    case 3:
                        Market();
                        break;
                    case 4:
                        Food();
                        break;
                    default:
                        Console.WriteLine("\t\t\t\t\t抱歉，您的输入有误，请重试");
                        break;
                }
            }
        }

        static void FrontDuang()
        {

            XDocument lineXml = XDocument.Load("..//..//xml//lineInfo.txt");
            XDocument hotelXml = XDocument.Load("..//..//xml//hotelInfo.txt");
            XDocument foodXml = XDocument.Load("..//..//xml//foodInfo.txt");
            XDocument marketXml = XDocument.Load("..//..//xml//marketInfo.txt");

            StatContrl.InitStationM(lineXml);
            StatContrl.InitNear(hotelXml);
            StatContrl.InitNear(foodXml);
            StatContrl.InitNear(marketXml);

            int flag = -1;
            string str = "";
            while (true)
            {
                Console.WriteLine("\t\t\t\t\t*****************************************************");
                Console.WriteLine("\t\t\t\t\t*        请输入操作码选择服务：                     *");
                Console.WriteLine("\t\t\t\t\t*         信息查询功能                              *");
                Console.WriteLine("\t\t\t\t\t*         1.指定站点附近的酒店,超市和美食信息       *");
                Console.WriteLine("\t\t\t\t\t*         2.距离指定站点最近的上述信息              *");
                Console.WriteLine("\t\t\t\t\t*         3.客户评价最好的酒店                      *");
                Console.WriteLine("\t\t\t\t\t*         4.指定酒店、超市和美食店所在的站点        *");
                Console.WriteLine("\t\t\t\t\t*---------------------------------------------------*");
                Console.WriteLine("\t\t\t\t\t*         出行规划功能                              *");
                Console.WriteLine("\t\t\t\t\t*         5.换乘次数最少                            *");
                Console.WriteLine("\t\t\t\t\t*         6.预计耗费时间最短                        *");
                Console.WriteLine("\t\t\t\t\t*         7.票价总和最小                            *");
                Console.WriteLine("\t\t\t\t\t*****************************************************");

                Console.Write("\t\t\t\t\t");
                try
                {
                    flag = int.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("\t\t\t\t\t抱歉，请输入有效的操作码");
                    continue;
                }
                
                switch (flag)
                {
                    
                    case 1:
                        Console.Write("\t\t\t\t\t请输入指定站点：");
                        str= Console.ReadLine();
                        StatContrl.CheckStation(str,5);
                        break;
                    case 2:
                        Console.Write("\t\t\t\t\t请输入指定站点：");
                         str = Console.ReadLine();
                        StatContrl.CheckStationNearest(str, 5);
                        break;
                    case 3:
                        StatContrl.FindBestScoreHotel();
                        break;
                    case 4:
                        Console.Write("\t\t\t\t\t请输入:1.指定饭店；2.指定酒店；3.指定超市");
                        int num = int.Parse(Console.ReadLine());
                        Console.Write("\t\t\t\t\t这个东西叫什么？");
                        string name = Console.ReadLine();
                        StatContrl.FindStationByNear(name, num);
                        break;
                    case 5:
                        Console.Write("\t\t\t\t\t请输入起点站：");
                        string start0 = Console.ReadLine();
                        Console.Write("\t\t\t\t\t请输入终点站：");
                        string end0 = Console.ReadLine();
                        StatContrl.LeastChange(start0,end0);
                        break;
                    case 6:
                        Console.Write("\t\t\t\t\t请输入起点站：");
                        string start1 = Console.ReadLine();
                        Console.Write("\t\t\t\t\t请输入终点站：");
                        string end1 = Console.ReadLine();
                        StatContrl.LeastTime(start1,end1);
                        break;
                    case 7:
                        Console.Write("\t\t\t\t\t请输入起点站：");
                        string start2 = Console.ReadLine();
                        Console.Write("\t\t\t\t\t请输入终点站：");
                        string end2 = Console.ReadLine();
                        StatContrl.LeastMoney(start2, end2);
                        break;
                    default:
                        Console.WriteLine("\t\t\t\t\t抱歉，您的输入有误，请重试");
                        break;
                }
            }
        }
       

    }
}
